package com.kui.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kui.entity.Type;
import com.kui.util.DBHelp;
import com.kui.util.RowMapper;

public class TypeDao {

	DBHelp<Type> db = new DBHelp<Type>();
	
	private class TypeRowMapper implements RowMapper<Type>{

		public Type mapperRow(ResultSet rs) throws SQLException {
			Type t = new Type();
			t.setId(rs.getString("id"));
			t.setName(rs.getString("name"));
			t.setT_qikan_id(rs.getString("t_qikan_id"));
			return t;
		}
		
	}

	public Type findById(String bianhao,String qikan) {
		String sql = "SELECT id,name,t_qikan_id FROM t_type WHERE id = ? and t_qikan_id = ?";
		
		return db.executeQueryForObject(sql, new TypeRowMapper(), bianhao,qikan);
	}

	public void save(Type tt) {
		String sql = "INSERT INTO t_type(id,name,t_qikan_id) VALUES(?,?,?)";
		db.executeSQL(sql, tt.getId(),tt.getName(),tt.getT_qikan_id());
		
	}

	public List<Type> findByQikanId(String value) {
		String sql = "SELECT id,name,t_qikan_id FROM t_type WHERE t_qikan_id = ?";
		return db.executeQueryForList(sql, new TypeRowMapper(), value);
	}

	public List<Type> findAll() {
		String sql = "SELECT distinct id,name,id AS t_qikan_id FROM t_type";
		return db.executeQueryForList(sql, new TypeRowMapper());
	}
}
